<?php

namespace App\Http\Controllers\Api\v1;

use App\Models\Question;
use App\Models\Article;
use App\Models\Banner;
use App\Models\Api\Recode;
use App\Models\System;
use App\Tools\Astrolog\Astrolog;
use App\Models\Api\User;
use App\Models\Api\FortuneCache;
use App\Tools\Base\Common;
use App\Tools\Base\Auth;
use App\Http\Controllers\Controller;

use App\Http\Controllers\Api\v1\Everyday\IndexController as Day;
use DB;
class NotindexController extends Controller
{

     public function __construct()
    {
        // Constructor code if needed
    }
    /**
     * @return \Illuminate\Http\JsonResponse
     * 首页查询
     */
    public function index(){
         $auth = new Auth();
         var_dump($auth);die;
         if (!$auth->isLogin()) {
            $data = [
                'message' => 'You are not logged in. Displaying alternative data.',
            ];

           return show(200,'首页加载成功',$data);
        }
        // $data['slides'] = Banner::where(['status'=>1,'cid'=>1])->get();
         $slide = (new Banner())->getSlide();
         $buttons = DB::table('button')->where('status',1)->get(['name','icon','type']);
         $article = Article::with(['user'=>function($query){
             $query->select('id','nickname','avatar');
         }])
        ->where('status',1)
        ->OrderBy('created_at','desc')
        ->limit(3)
        ->get(['id','created_at','title','tag','img','auth','desc','watch','count_like']);
         $questions = Question::with(['user'=>function($query){
             $query->select('id','nickname','avatar');
         }])
            ->where('answerer_num','<>',function ($query){$query->select('answerer_now');})
            ->where('state',1)
            ->where('parent_id',0)
            ->OrderBy('created_at','desc')
            ->limit(5)
            ->get(['id','user_id','type','question','money','answerer_num','answerer_now','pv','created_at','pay_type']);
             $new_time = strtotime (date("y-m-d H:i:s"));
        foreach ($questions as $question){

            $time = floor($new_time - strtotime($question->created_at));

            if ($time <=60){
                $question->time = '刚刚';
            }elseif($time <=120 && $time >60){
                $question->time = '1分钟前';
            }elseif ($time <=180 && $time >120){
                $question->time = '2分钟前';
            }elseif($time <=1800 && $time>180){
                $question->time = '半小时前';
            }elseif ($time <=3600 && $time>1800){
                $question->time = '一小时前';
            }elseif ($time<=7200 && $time>3600){
                $question->time = '两小时前';
            }else{
                $question->time = $question->created_at;
            }
        }


         $data = [
            'in_sign' => '7',
            'slides' => $slide,
            'buttons' => $buttons,
            "today_fortune" => [
                "revive_day" => [
                "name" => "快乐之日",
                "star_level" => 1,
                "tips" => "会有开心的事情发生，虽然大多离不开吃喝玩乐。旅行，聚会，庆祝，结识新朋友，谈恋爱，打游戏……你有种种可能，总之今天一定有办法让自己开心。告白、求婚、调解关系、洽谈合作也是不错的选择。",
                "icon_url" => "https://oss.goddessxzns.com/upload/icon/love.png",
                "tips_url" => "https://oss.goddessxzns.com/upload/icon/love_pop.png"
              ],
                "lucky_name" => [
                 "0" => "调节身心",
                 "1" => "享受美食"
               ],
                 "forbid_name" => [
                 "0" => "轻易动情"
              ]
               ],
              'content' => '999',
              "today_astro" => [
                "time" => time(),
                "tips" => "太阳在处女座，木星逆行，木星停滞，土星逆行，土星停滞，大三角"
             ],
            "article" => [
      "0" => [
        "id" => 30,
        "created_at" => "2019-06-14 10:03:12",
        "title" => "6月14日十二星座塔罗运势",
        "tag" => null,
        "img" => "upload/493cd0a282b215ec51bd930069ea0717.png",
        "auth" => "10254596",
        "desc" => "6月14日十二星座塔罗运势",
        "watch" => 2,
        "count_like" => "0",
        "user" => [
          "id" => 10254596,
          "nickname" => "kingcode",
          "avatar" => "upload/2019/10254596/ca4fa7ba100543c146d13cc2185bc0b8.png"
        ]
      ],
      "1" => [
        "id" => 29,
        "created_at" => "2019-06-13 15:22:10",
        "title" => "6月13日十二星座塔罗运势",
        "tag" => null,
        "img" => "upload/899b6d889d08de0ef9c09d67d2755d18.png",
        "auth" => "10254596",
        "desc" => "6月13日十二星座塔罗运势",
        "watch" => 42,
        "count_like" => "1",
        "user" => [
          "id" => 10254596,
          "nickname" => "kingcode",
          "avatar" => "upload/2019/10254596/ca4fa7ba100543c146d13cc2185bc0b8.png"
        ]
      ],
      "2" => [
        "id" => 28,
        "created_at" => "2019-06-12 09:35:00",
        "title" => "6月12日十二星座塔罗运势",
        "tag" => null,
        "img" => "upload/ffc81ba7b663269a861847cc6a55b912.png",
        "auth" => "10254596",
        "desc" => "6月12日十二星座塔罗运势",
        "watch" => 13,
        "count_like" => "0",
        "user" => [
          "id" => 10254596,
          "nickname" => "kingcode",
          "avatar" => "upload/2019/10254596/ca4fa7ba100543c146d13cc2185bc0b8.png"
        ]
      ]
    ],
            //'questions' =>$questions,
            'lucky_planet_switch' => false,// 幸运星功能开关
        ];

         return show(200,'首页加载成功',$data);
         //return show(200,'首页加载成功',(new \App\Tools\Aes())->encryptWithOpenssl(json_encode($data)));
    }
}
